package uebungsblatt09.aufgabe15a;

import java.io.Serializable;
import java.util.ArrayList;

public class Model implements Serializable
{
	private static final long serialVersionUID = 6695684664055633206L;
	
	private int w;
	private ArrayList<ModelListener> listeners;
	private ArrayList<Controller> controllers;
	
	public Model()
	{
		listeners = new ArrayList<ModelListener>();
		controllers = new ArrayList<Controller>();
	}
	
	public void addModelListener(ModelListener listener)
	{
		listeners.add(listener);
	}
	
	public void addController(Controller controller)
	{
		controllers.add(controller);
	}
	
	private void fireModelChanged()
	{
		for(ModelListener listener : listeners)
			listener.modelChanged();
	}
	
	public void setW(int w)
	{
		this.w = w;
		fireModelChanged();
	}
	
	public int getW()
	{
		return w;
	}
	
	public void setControllers(ArrayList<Controller> controllers)
	{
		this.controllers = controllers;
	}
	
	public void setModelListeners(ArrayList<ModelListener> listeners)
	{
		this.listeners = listeners;
	}
	
	public ArrayList<Controller> getControllers()
	{
		return controllers;
	}
	
	public ArrayList<ModelListener> getModelListeners()
	{
		return listeners;
	}
}
